home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / Libraries / DCLAP 6d / dclap6d / DClap / DControl.cpp < prev    next >
Text File  |  1996-07-05  |  7KB  |  320 lines

  1. // DControl.cp
  2. // d.g.gilbert
  3.  
  4.  
  5. #include "Dvibrant.h"
  6. #include "DControl.h"
  7. #include "DList.h"
  8. #include "DUtil.h"
  9.  
  10.  
  11.  
  12.  
  13. // class DControl  
  14.  
  15.  
  16.  
  17.  
  18. // class DCluster : DControl
  19.  
  20. extern "C" void groupActionProc(Nlm_GrouP    item)
  21. {
  22.     DCluster *obj= (DCluster*) Nlm_GetObject( (Nlm_GraphiC)item);
  23.     if (obj)  obj->IsMyViewAction(obj);
  24. }
  25.  
  26.  
  27. // fFont and SetFont are static
  28. Nlm_FonT DCluster::fFont = NULL;
  29.  
  30. void DCluster::SetFont( Nlm_FonT theFont)
  31. {
  32.     fFont= theFont;
  33. }
  34.  
  35.  
  36. DCluster::DCluster(long id, DView* itsSuperior, 
  37.     short width, short height, Boolean hidden, char* title) :
  38.     DControl( id, itsSuperior) 
  39.     if (hidden)
  40.         fGroup= Nlm_HiddenGroup( (Nlm_WindoW)itsSuperior->GetNlmObject(), width, height, 
  41.             groupActionProc);
  42.     else
  43.         fGroup= Nlm_NormalGroup( (Nlm_WindoW)itsSuperior->GetNlmObject(), width, height, title, 
  44.             fFont, groupActionProc);
  45.     this->SetNlmObject(fGroup);    
  46. }
  47.  
  48. DCluster::~DCluster()
  49. {
  50.  
  51. }
  52.  
  53.  
  54. //class DPrompt : public DControl
  55.  
  56. DPrompt::DPrompt(long id, DView* itsSuperior, char* title, short pixwidth, short pixheight, 
  57.     Nlm_FonT font, Justify just) :
  58.     DControl( id, itsSuperior) 
  59. {
  60.     fPrompt= Nlm_StaticPrompt((Nlm_WindoW)itsSuperior->GetNlmObject(), title, pixwidth, 
  61.                                 pixheight, font, just);  
  62.     this->SetNlmObject(fPrompt);    
  63. }
  64.  
  65.  
  66.  
  67.  
  68.     
  69.  
  70.  
  71.  
  72. class DString2 : public DObject
  73. {
  74.     char * fStr, * fStr2;
  75. public:
  76.     DString2(): fStr(NULL), fStr2(NULL) { }
  77.     DString2(const char* s1, const char* s2= NULL) { 
  78.         fStr= StrDup((char*) s1); 
  79.         fStr2= StrDup((char*) s2); 
  80.         }
  81.     virtual ~DString2() { MemFree(fStr); MemFree(fStr2); }
  82.     virtual const char* Get() { return fStr; }
  83.     virtual const char* Get2() { return fStr2; }
  84.     virtual void Set(const char* s) { MemFree(fStr); fStr= StrDup((char*) s); }
  85.     virtual void Set2(const char* s2) { MemFree(fStr2); fStr2= StrDup((char*) s2); }
  86. };
  87.  
  88.  
  89.  
  90. //class DPopupList : public DView
  91.     
  92. extern "C" void PopupListHandler(Nlm_PopuP p)
  93. {
  94.     DPopupList *obj= (DPopupList*) Nlm_GetObject((Nlm_GraphiC)p);
  95.     if (obj) obj->IsMyViewAction(obj);
  96. }
  97.  
  98. DPopupList::DPopupList(long id, DView* itsSuperior, Boolean macLike) :
  99.     DControl( id, itsSuperior) 
  100. {
  101.     fPopup= Nlm_PopupList((Nlm_GrouP)itsSuperior->GetNlmObject(), macLike, PopupListHandler);
  102.     this->SetNlmObject(fPopup);
  103.     //gViewCentral->RegisterView(id, fPopup, kMenu, this); << done by ::DView() 
  104.     //fItemList= new DList(NULL,DList::kOwnObjects + DList::kDeleteObjects);
  105.     fItemList= new DList(NULL);
  106. }
  107.  
  108.  
  109. DPopupList::~DPopupList()
  110. {
  111.     // dammit, DList( , kDeleteObjects) is NOT WORKING !! (not called obj destructors)
  112.     short i, n= fItemList->GetSize();
  113.     for (i=0; i<n; i++) {
  114.         DString2* st= (DString2*) fItemList->At(i);
  115.         delete st;
  116.         }
  117.     delete fItemList;
  118. }
  119.  
  120. #if FIX_THIS_LATER
  121. void  DPopupList::SetItemState(short item, Boolean enable) 
  122. {
  123.     DView* aview= (DView*)fPopupItemList->At(item);
  124.     if (aview) vobj= aview->fNlmObject;
  125.     if (enable) 
  126.         Nlm_EnableChoiceItem ( vobj, false, false);
  127.     else
  128.         Nlm_DisableChoiceItem ( vobj, false, false);
  129. }
  130. #endif
  131.  
  132. void  DPopupList::AddItem(char* title, char* value) 
  133. {
  134.     DString2* s= new DString2(title, value);
  135.     fItemList->InsertLast(s);
  136.     Nlm_PopupItem(fPopup, title);
  137. }
  138.  
  139. char* DPopupList::GetItemTitleOrValue( short item, char* title, ulong maxsize, 
  140.         Boolean getval2) 
  141.   if (item>0) {
  142.       DString2* s= (DString2*) fItemList->At(item-1);
  143.       if (s) {
  144.             char *cp;
  145.             if (getval2) cp= (char*) s->Get2();
  146.             else cp= (char*) s->Get();
  147.             if (title==NULL) {
  148.               maxsize= StrLen(cp) + 1;
  149.               title= (char*) MemNew(maxsize);
  150.               }
  151.             StrNCpy(title, cp, maxsize);
  152.             }
  153.         }
  154.     return title;
  155. }
  156.  
  157.  
  158. char* DPopupList::GetSelectedItem( short& item, char* name, ulong namesize) 
  159.     item= GetValue(); 
  160.     return this->GetItemTitleOrValue( item, name, namesize, false);
  161. }
  162.  
  163. char* DPopupList::GetSelectedValue( short& item, char* name, ulong namesize) 
  164.     item= GetValue(); 
  165.     return this->GetItemTitleOrValue( item, name, namesize, true);
  166. }
  167.  
  168.  
  169.  
  170.  
  171.  
  172.  
  173. extern "C" void buttonActionProc(Nlm_ButtoN    item)
  174. {
  175.     DButton *obj= (DButton*) Nlm_GetObject( (Nlm_GraphiC)item);
  176.     if (obj)  obj->IsMyViewAction(obj);
  177. }
  178.  
  179. //class DButton : public DControl
  180.  
  181. DButton::DButton(long id, DView* itsSuperior, char* title):
  182.     DControl( id, itsSuperior) 
  183. {
  184.     fButton    = Nlm_PushButton( (Nlm_WindoW)itsSuperior->GetNlmObject(), title, buttonActionProc);
  185.     this->SetNlmObject(fButton);    
  186. }
  187.  
  188.  
  189. //class DDefaultButton : public DButton
  190.  
  191. DDefaultButton::DDefaultButton(long id, DView* itsSuperior, char* title):
  192.     DControl( id, itsSuperior) 
  193. {
  194.     fButton    = Nlm_DefaultButton((Nlm_WindoW)itsSuperior->GetNlmObject(), title, buttonActionProc);
  195.     this->SetNlmObject(fButton);    
  196. }
  197.  
  198.  
  199. //class DCheckBox : public DButton
  200.  
  201. DCheckBox::DCheckBox(long id, DView* itsSuperior, char* title):
  202.     DControl( id, itsSuperior) 
  203. {
  204.     fButton    = Nlm_CheckBox((Nlm_WindoW)itsSuperior->GetNlmObject(), title, buttonActionProc);
  205.     this->SetNlmObject(fButton);    
  206. }
  207.  
  208. //class DRadioButton : public DButton
  209.  
  210. DRadioButton::DRadioButton(long id, DView* itsSuperior, char* title):
  211.     DControl( id, itsSuperior) 
  212. {
  213.     fButton    = Nlm_RadioButton((Nlm_WindoW)itsSuperior->GetNlmObject(), title);
  214.     this->SetNlmObject(fButton);    
  215. }
  216.  
  217.  
  218.  
  219.  
  220.  
  221. //class DListBox : public DControl
  222.  
  223.  
  224. extern "C" void listboxActionProc(Nlm_LisT    item)
  225. {
  226.     DListBox *obj= (DListBox*) Nlm_GetObject( (Nlm_GraphiC)item);
  227.     if (obj)  obj->IsMyViewAction(obj);
  228. }
  229.  
  230. DListBox::DListBox(long id, DView* itsSuperior, 
  231.     short width, short height, Boolean multiselection):
  232.     DControl( id, itsSuperior) 
  233. {
  234.     if (multiselection)
  235.         fListBox= Nlm_MultiList((Nlm_WindoW)itsSuperior->GetNlmObject(), width, height, listboxActionProc);
  236.     else
  237.         fListBox= Nlm_SingleList((Nlm_WindoW)itsSuperior->GetNlmObject(), width, height, listboxActionProc);
  238.     this->SetNlmObject(fListBox);    
  239. }
  240.  
  241.  
  242.  
  243. //class DRepeatButton : public DControl
  244.  
  245. extern "C" void repeaterProc(Nlm_RepeaT item, Nlm_PoinT mouse)
  246. {
  247.     DRepeatButton *obj= (DRepeatButton*) Nlm_GetObject( (Nlm_GraphiC)item);
  248.     if (obj) obj->ClickAt(mouse);
  249. }
  250.  
  251. DRepeatButton::DRepeatButton(long id, DView* itsSuperior, char* title):
  252.     DControl( id, itsSuperior) 
  253. {
  254.     fRepeater= Nlm_RepeatButton((Nlm_WindoW)itsSuperior->GetNlmObject(), title, repeaterProc);
  255.     this->SetNlmObject(fRepeater);    
  256. }
  257.  
  258. void DRepeatButton::ClickAt( Nlm_PoinT mouse)
  259. {
  260.  
  261. }
  262.  
  263.  
  264.  
  265.  
  266. //class DScrollBar : public DControl
  267.  
  268. extern "C" void scrollbarProc(Nlm_BaR item, Nlm_GraphiC itsSlave, Nlm_Int2 newval, Nlm_Int2 oldval)
  269. {
  270.     DScrollBar *obj= (DScrollBar*) Nlm_GetObject( (Nlm_GraphiC)item);
  271.     DView *scrollee= (DView*) Nlm_GetObject( itsSlave);
  272.     // scrollee should == itsSuperior 
  273.     if (obj)  obj->Scroll(scrollee,newval,oldval);
  274. }
  275.  
  276. DScrollBar::DScrollBar(long id, DView* itsSuperior, short width, short height):
  277.     DControl( id, itsSuperior)
  278. {
  279.     fScrollbar=  Nlm_ScrollBar((Nlm_WindoW)itsSuperior->GetNlmObject(), width, height, scrollbarProc);
  280.     this->SetNlmObject(fScrollbar);    
  281. }
  282.  
  283. void DScrollBar::Scroll(DView* scrollee, short newval, short oldval)
  284. {
  285.     
  286. }
  287.  
  288.  
  289.  
  290.  
  291.  
  292. //class DSwitchBox : public DControl
  293.  
  294. extern "C" void switchProc(Nlm_SwitcH    item, short newval, short oldval)
  295. {
  296.     DSwitchBox *obj= (DSwitchBox*) Nlm_GetObject( (Nlm_GraphiC)item);
  297.     if (obj)  obj->Switch(newval, oldval);
  298. }
  299.  
  300. DSwitchBox::DSwitchBox(long id, DView* itsSuperior, Boolean displayTextOfValue, Boolean vertical):
  301.     DControl( id, itsSuperior)
  302. {
  303.     if (vertical)
  304.         fSwitch= Nlm_UpDownSwitch((Nlm_WindoW)itsSuperior->GetNlmObject(), displayTextOfValue, switchProc);
  305.     else
  306.         fSwitch= Nlm_LeftRightSwitch((Nlm_WindoW)itsSuperior->GetNlmObject(), displayTextOfValue, switchProc);
  307.     this->SetNlmObject(fSwitch);    
  308. }
  309.  
  310. void DSwitchBox::Switch(short newval, short oldval)
  311. {
  312.     
  313. }
  314.  
  315.  
  316.